import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_widgets/widgets/detailsItemView/kq_details_item_view.dart';
import 'package:kq_flutter_widgets/widgets/expandableList/kq_expand_group.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

/// 可收缩列表demo
///
/// @author 周卓
///
class ExpandListDemoPage extends StatefulWidget {
  const ExpandListDemoPage({Key? key}) : super(key: key);

  @override
  _ExpandListDemoPageState createState() => _ExpandListDemoPageState();
}

class _ExpandListDemoPageState extends State<ExpandListDemoPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '折叠列表演示',
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            KqExpandGroup(headerWidget: _buildHeader('设备1#'), childWidgets: [
              _buildChildItem('设备1#参数名称1', '111'),
              _buildChildItem('设备1#参数名称2', '2222'),
              KqExpandGroup(
                headerExtraPaddingLeft: 20.r,
                childPaddingLeft: 20.r,
                headerWidget: _buildHeader('机械手'),
                childWidgets: [
                  _buildChildItem('机械手参数名称1', '111'),
                  _buildChildItem('机械手参数名称2', '222'),
                ],
              ),
            ]),
            KqExpandGroup(
                arrowPosition: ArrowPosition.left,
                arrowHeaderSpacing: 10.r,
                headerWidget: _buildHeader('设备2#'),
                childWidgets: [
                  _buildChildItem('设备2#参数名称1', '111'),
                  _buildChildItem('设备2#参数名称2', '2222'),
                  KqExpandGroup(
                    headerExtraPaddingLeft: 20.r,
                    childPaddingLeft: 20.r,
                    headerWidget: _buildHeader('子设备1'),
                    childWidgets: [
                      _buildChildItem('子设备1参数名称1', '111'),
                      _buildChildItem('子设备1参数名称2', '222'),
                    ],
                  ),
                ]),
          ],
        ),
      ),
    );
  }

  Widget _buildHeader(String title) {
    return Text(
      title,
      style: TextStyle(fontSize: 16.sp, color: KqThemeColors.text26),
    );
  }

  Widget _buildChildItem(String title, String content) {
    return KqDetailsItemView(
      title: title,
      content: content,
      hideDivider: true,
    );
  }
}
